package com.dcms.admin.controller;

import com.dcms.admin.bean.Log;
import com.dcms.admin.service.ILogService;
import com.dcms.util.layui.LayTable;
import com.dcms.util.ResultBean;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping("admin/log")
public class LogController extends BaseController{

    @Autowired
    private ILogService logService;

    @RequestMapping("query")
    @ResponseBody
    public LayTable<Log> query(
            String param,
            Log record,
            Integer limit,
            Integer page
    ){
        page = page == null ? 1 : page;
        limit = limit == null ? 12 : limit;

        PageHelper.startPage(page, limit);
        List<Log> list = logService.selectAll(param, record);
        PageInfo<Log> info = new PageInfo<Log>(list);
        LayTable<Log> bean = new LayTable<Log>(info.getList(), (int)info.getTotal());
        return bean;
    }

    /**
     * @author: 武佳伟丶
     * @description: 更新
     * @date: 18:55 2018/2/13 0013
     * @param: [record]
     * @return: com.dcms.util.ResultBean
     */
    @RequestMapping(value = "update", method = RequestMethod.POST)
    @ResponseBody
    public ResultBean update(Log record){
        int rows = logService.updateByPrimaryKeySelective(record);
        if (rows > 0){
            return new ResultBean();
        }
        return new ResultBean(10021);
    }

}